  package edu.hawaii.halealohacli;

  import static org.junit.Assert.assertEquals;
  import static org.junit.Assert.assertTrue;
  import org.junit.Test;
  import org.wattdepot.client.WattDepotClient;
  /**
   * Test cases for MonitorGoal.
   * @author Daniel Ly
   *
   */
public class TestMonitorGoal {

    // URL to the WattDepot server
    String url = "http://server.wattdepot.org:8190/wattdepot/";
    // Create a WattDepotClient with URL
    WattDepotClient client = new WattDepotClient(url);
    String towerName = "Mokihana";
    SetBaseline setBaseline = new SetBaseline(towerName, client);
    Baselist baselist = new Baselist();
    MonitorGoal monitorGoal = new MonitorGoal(towerName, client, 5, 15, baselist);

    /**
     * Checks to see if the values entered in the constructor for monitor-goal processes right.
     */
    @Test
    public void testValues() {
      assertEquals("Test to see if tower names match for default", towerName, 
          monitorGoal.getTower());
    }

    /**
     * Test that a printer thread can be created and stopped.
     */
    @Test
    public void testPrinter() {
      boolean succeeded = false;
      try {
        baselist.put(towerName, setBaseline.trueRun());
        PrinterThread2 printer = new PrinterThread2(towerName, client, 5, 15,
           baselist.get(towerName));
        printer.start();
        Thread.sleep(2000);
        printer.exit();
        printer.interrupt();
        succeeded = true;
      }
      catch (Exception e) {
        succeeded = false;
      }
      assertTrue("Thread couldn't be created and stopped", succeeded);
    }
  }